<template>
  <div class="orders-container">
    <el-card>
      <template #header>
        <div class="header">
          <span>订单管理</span>
          <el-form :inline="true" :model="searchForm">
            <el-form-item>
              <el-input
                v-model="searchForm.orderNo"
                placeholder="订单号"
                clearable
              />
            </el-form-item>
            <el-form-item>
              <el-select v-model="searchForm.status" placeholder="订单状态" clearable>
                <el-option label="待支付" value="PENDING" />
                <el-option label="已支付" value="PAID" />
                <el-option label="已完成" value="COMPLETED" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
            </el-form-item>
          </el-form>
        </div>
      </template>

      <el-table :data="tableData" border v-loading="loading">
        <el-table-column prop="orderNo" label="订单号" />
        <el-table-column prop="createTime" label="下单时间" />
        <el-table-column prop="status" label="状态">
          <template #default="{ row }">
            <el-tag :type="getStatusType(row.status)">
              {{ getStatusText(row.status) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="金额" />
        <el-table-column label="操作" width="200">
          <template #default="{ row }">
            <el-button type="primary" link @click="handleDetail(row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :total="total"
          @current-change="handlePageChange"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'

const searchForm = reactive({
  orderNo: '',
  status: ''
})

const loading = ref(false)
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
const tableData = ref([])

const getStatusType = (status) => {
  const map = {
    PENDING: 'warning',
    PAID: 'success',
    COMPLETED: 'info'
  }
  return map[status]
}

const getStatusText = (status) => {
  const map = {
    PENDING: '待支付',
    PAID: '已支付',
    COMPLETED: '已完成'
  }
  return map[status]
}

const handleSearch = () => {
  // TODO: 实现搜索逻辑
}

const handleDetail = (row) => {
  // TODO: 实现查看详情逻辑
}

const handlePageChange = (page) => {
  currentPage.value = page
  // TODO: 重新加载数据
}
</script>

<style scoped lang="scss">
.orders-container {
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  
  .pagination {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
  }
}
</style> 